// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: leon

#include "coin2/exchange/factory/feed/latency_extractor.h"

#include <memory>
#include <string>

#include "coin2/exchange/base/market/enums.h"
#include "coin2/exchange/binance_base/feed_v1/latency_extractor.h"
#include "coin2/exchange/okex_common/feed_v3/latency_extractor.h"
#include "coin2/exchange/okex_common/feed_v5/latency_extractor.h"

namespace coin2::exchange::factory::feed {
namespace impl {

using namespace coin::proto;

std::shared_ptr<base::feed::LatencyExtractor> NewLatencyExtractor(
    const MarketExchangeApi& mea) {
  if (mea == MarketExchangeApi {Spot, Okex, "v3"} ||
      mea == MarketExchangeApi {Futures, Okex, "v3"} ||
      mea == MarketExchangeApi {Futures, Okex, "v3-swap"}) {
    return std::make_shared<okex_common::feed_v3::OkexCommonLatencyExtractor>();
  } else if (mea == MarketExchangeApi {Spot, Okex, "v5"} ||
      mea == MarketExchangeApi {Futures, Okex, "v5"} ||
      mea == MarketExchangeApi {Futures, Okex, "v5-swap"}) {
    return std::make_shared<okex_common::feed_v5::OkexCommonLatencyExtractor>();
  } else if (
      (mea == MarketExchangeApi {Futures, Binance, "v1"}) ||
      (mea == MarketExchangeApi {Futures, Binance, "v1-delivery"}) ||
      (mea == MarketExchangeApi {Spot, Binance, "v1"})) {
    return std::make_shared<binance_base::feed_v1::BinanceBaseLatencyExtractor>();
  } else {
    THROW() << "[Latency Extractor] not implemented for " << mea.String();
  }
  return nullptr;
}
}  // namespace impl
using impl::NewLatencyExtractor;
}  // namespace coin2::exchange::factory::feed
